/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package arrayManipulation;

import java.util.Random;

/**
 *
 * @author Du
 */
public class Qsort {

    public Qsort(int[] v, int ini, int fim) {
        quick_sort(v, ini, fim);
    }

    public static void quick_sort(int[] v, int ini, int fim) {
        int meio;

        if (ini < fim) {
            meio = partition(v, ini, fim);
            quick_sort(v, ini, meio);
            quick_sort(v, meio + 1, fim);
        }
    }

    public static int partition(int[] v, int ini, int fim) {
        int pivo, topo, i;
        pivo = v[ini];
        topo = ini;

        for (i = ini + 1; i < fim; i++) {
            if (v[i] < pivo) {
                v[topo] = v[i];
                v[i] = v[topo + 1];
                topo++;
            }
        }
        v[topo] = pivo;
        return topo;
    }
    
    public static void generateRandom(int[] vet) {
        Random randNum = new Random();

        for (int i=0; i<vet.length; i++) {
            vet[i] = randNum.nextInt(1000);
        }

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int[] vet = new int[125];
        /*byte [] byteVect = new byte[args[1].length()];
        byteVect = args[1].getBytes();
        vet = byteToInt(byteVect);*/
        
        generateRandom(vet);

        System.out.println("antes:");

        for (int i = 0; i < vet.length; i++) {
            System.out.println(vet[i]);
        }

        Qsort ordena = new Qsort(vet, 0, vet.length);
        System.out.println("depois:");

        for (int i = 0; i < vet.length; i++) {
            System.out.println(vet[i]);
        }
    }
}

